package com.doubao.user.client.fallback;

import com.doubao.common.result.Result;
import com.doubao.user.client.PaymentClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 支付服务客户端降级处理
 */
@Component
@Slf4j
public class PaymentClientFallback implements PaymentClient {

    private static final String ERROR_MESSAGE = "支付服务暂不可用，请稍后再试";

    @Override
    public Result<Map<String, Object>> createOrder(Long userId, Long productId, Integer amount, String subject, 
                                                 String body, String payChannel, String payType, 
                                                 String attach, String clientIp) {
        log.error("支付服务调用失败-创建订单: userId={}, productId={}, amount={}", userId, productId, amount);
        return Result.failed(ERROR_MESSAGE);
    }

    @Override
    public Result<Map<String, Object>> getOrderByOutTradeNo(Long userId, String outTradeNo) {
        log.error("支付服务调用失败-查询订单: userId={}, outTradeNo={}", userId, outTradeNo);
        return Result.failed(ERROR_MESSAGE);
    }

    @Override
    public Result<Void> closeOrder(Long userId, String outTradeNo) {
        log.error("支付服务调用失败-关闭订单: userId={}, outTradeNo={}", userId, outTradeNo);
        return Result.failed(ERROR_MESSAGE);
    }

    @Override
    public Result<Map<String, Object>> createMembershipOrder(Long userId, Long membershipId, 
                                                           Integer amount, String payType, String clientIp) {
        log.error("支付服务调用失败-创建会员订单: userId={}, membershipId={}, amount={}", 
                userId, membershipId, amount);
        return Result.failed(ERROR_MESSAGE);
    }

    @Override
    public Result<Map<String, Object>> queryMembershipOrder(String outTradeNo, Long userId) {
        log.error("支付服务调用失败-查询会员订单: outTradeNo={}, userId={}", outTradeNo, userId);
        Map<String, Object> emptyData = new HashMap<>();
        emptyData.put("status", "UNKNOWN");
        return Result.failed(ERROR_MESSAGE);
    }

    @Override
    public Result<Void> handlePaymentCallback(String outTradeNo, String transactionId, Long userId) {
        log.error("支付服务调用失败-支付回调: outTradeNo={}, transactionId={}, userId={}", 
                outTradeNo, transactionId, userId);
        return Result.failed(ERROR_MESSAGE);
    }
} 